import os
import sys

import torch
from PyQt5.QtGui import QIcon
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtWidgets import QFileDialog
from torch import nn

from Alex_net_cat_dog import classfiey
from UI import Ui_MainWindow

# %%模型加载

img_2 = 0
filepath = 0


def get_pic():
    filePath, _ = QFileDialog.getOpenFileName(
        None,
        "选择你要上传的图片",  # 标题
        "./",  # 起始目录
        "图片类型 (*.png *.jpg *.bmp)"  # 选择类型过滤项，过滤内容在括号中
    )
    print(filePath)
    print(os.path.abspath(filePath))
    pix = QPixmap(filePath)
    ui.label.setPixmap(pix)
    var = classfiey(filePath)
    print(var)
    ui.textBrowser.clear()
    ui.textBrowser.setText('鉴定为：' + var)
    # filepath=filePath


app = QApplication(sys.argv)  # 创建应用程序
app.setWindowIcon(QIcon('logo.png'))
mainwindow = QMainWindow()  # 创建主窗口
ui = Ui_MainWindow()  # 调用first中的主窗口
ui.setupUi(mainwindow)  # 向主窗口添加控件
mainwindow.setFixedSize(887, 563)
ui.pushButton.clicked.connect(get_pic)
ui.textBrowser.setFontPointSize(20)

mainwindow.show()  # 显示窗口
sys.exit(app.exec_())  # 程序执行循环
